package com.threeti.mecool.legacy.domain.model.basicdata;

import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;

public class MDBrand {
    private String code;
    private String name;
    private MDCategory category;
    private Set<MDProduct> products = new LinkedHashSet<MDProduct>();

    public MDBrand(String code, String name, MDCategory category) {
        this.code = code;
        this.name = name;
        this.category = category;
        category.addBrands(this);
    }

    void addProducts(MDProduct product) {
        products.add(product);
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public MDCategory getCategory() {
        return category;
    }

    public Collection<MDProduct> getProducts() {
        return Collections.unmodifiableCollection(products);
    }

    @Override
    public int hashCode() {
        return code != null ? code.hashCode() : super.hashCode();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (code != null && obj instanceof MDBrand) {
            return code.equals(((MDBrand) obj).code);
        }
        return false;
    }
}
